package com.example.eventlistener.listener;

import com.example.eventlistener.bean.User;
import com.example.eventlistener.event.UserEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 非注解声明的Listener需要继承ApplicationListener
 * 非注解声明的Listener缺省是同步模式, 如果想使用异步事件接受则需要配置ApplicationEventMulticaster为异步,
 * @see com.example.eventlistener.config.AsyncEventConfig
 */
@Component
public class NormalListener implements ApplicationListener<UserEvent> {
    @Override
    public void onApplicationEvent(UserEvent event) {
        User user = event.getUser();
        // 对于user对象的业务处理
        System.out.println("!!!!: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
        System.out.println("Observe event happening: " + user);
    }
}
